﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Random = UnityEngine.Random;

public class TongXunLuManager : MonoBehaviour
{
    public Transform content;
    public Transform content2;

    [HideInInspector]
    public GameObject This;

    public GameObject LinePrefab;
    public GameObject NPC_Cell;

    public Button create;
    public Button delete;

    [HideInInspector]
    public GameObject SelectRelation;

    [HideInInspector]
    public NPCs[] npc;

    void Start()
    {
        npc = GameObject.Find("GameManager").GetComponent<NPCManager>().NPC;
        for (int i = 0; i < npc.Length; i++)
        {
            NPC_Cell.GetComponentInChildren<TongXunLu_Cell>().t.text = npc[i].name;
            NPC_Cell.GetComponentInChildren<TongXunLu_Cell>().Head.sprite = npc[i].Head;
            Instantiate(NPC_Cell, new Vector3(Random.Range(-400, 400),Random.Range(-400, 400)), Quaternion.identity, content2);
        }
        create.onClick.AddListener(delegate
        {
            PlayerPrefs.SetInt("CreateRelation", 1);
        });
        delete.onClick.AddListener(delegate
        {
            Destroy(SelectRelation);
        });
    }

    public void CreateNewRelation(GameObject mTarget)
    {
        LinePrefab.GetComponent<Relation>().This = This;
        LinePrefab.GetComponent<Relation>().mTarget = mTarget;
        LinePrefab.GetComponent<Relation>().start = true;
        LinePrefab.name = "Relation";
        Instantiate(LinePrefab, content);
        GameObject.FindGameObjectWithTag("relation").GetComponent<Relation>().start = false;
    }
}
